package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsCategoryMapper;
import com.qf.pojo.DtsCategory;
import com.qf.service.DtsCategoryService;
import com.qf.vo.CatVo;
import com.qf.vo.CategorySellAmts;
import com.qf.vo.CategorySellVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Zwnan
 */
@Service
public class DtsCategoryServiceImpl implements DtsCategoryService {
    @Autowired
    private DtsCategoryMapper dtsCategoryMapper;

    @Override
    public CategorySellVo findCategorySell() {
        CategorySellVo categorySellVo = new CategorySellVo();
        List<CategorySellAmts> categorySellAmtsList = dtsCategoryMapper.findCategorySell();
        categorySellVo.setCategorySellData(categorySellAmtsList);
        List<String> collect = categorySellAmtsList.stream().map(CategorySellAmts::getName).collect(Collectors.toList());
        categorySellVo.setCategoryNames(collect);
        return categorySellVo;
    }

    @Override
    public List<CatVo> findName() {
        return dtsCategoryMapper.findName();
    }

    @Override
    public List<CatVo> findName2(Integer value) {
        return dtsCategoryMapper.findName2(value);
    }

    @Override
    public IPage<DtsCategory> findPage(Integer page, Integer limit, String sort, String order) {
        IPage<DtsCategory> iPage = new Page<>(page,limit);
        QueryWrapper queryWrapper = new QueryWrapper<DtsCategory>();
        queryWrapper.eq("deleted", false);
        return dtsCategoryMapper.selectPage(iPage,queryWrapper);
    }

    @Override
    public void create(DtsCategory dtsCategory) {
        dtsCategoryMapper.insert(dtsCategory);
    }

    @Override
    public void update(DtsCategory dtsCategory) {
        dtsCategoryMapper.updateById(dtsCategory);
    }

    @Override
    public void delete(DtsCategory dtsCategory) {
        dtsCategory.setDeleted(true);
        dtsCategoryMapper.updateById(dtsCategory);
    }

    @Override
    public String selectByPid(String l2) {
        return dtsCategoryMapper.selectByPid(l2);
    }
}
